/*
 * @Author: SakumyZ
 * @Date: 2019-02-22 22:20:48
 * @Description:  使用react达到数据的双向绑定
 * @Last Modified by: SakumyZ
 * @Last Modified time: 2019-02-22 23:04:03
 */

import React from 'react';

class BindInputValue extends React.Component {
  constructor() {
    super();
    this.state = {
      msg: ''
    };
  }

  render() {
    return (
      <input
        type="text"
        value={this.state.msg}
        onChange={e => {
          this.setInputValue(e);
        }}
      />
    );
  }

  setInputValue = e => {
    this.setState(
      {
        msg: e.target.value
      },
      () => {
        console.log(`%c 此时value为：${this.state.msg}`, 'color: blue');
      }
    );
  };
}

export default BindInputValue;
